package com.icare.common.service.utils;

import java.util.Arrays;

/**
 * 排序工具类
 *
 * @author TianHaibo
 * @create 2018-01-02 18:05
 **/
public class SortUtil {
    /**
     * 冒泡排序
     * @param src
     * @param isAsc
     * @return
     */
    public static Integer[] sort1(Integer[] src,boolean isAsc){
        if(src == null ) return null;
        Integer[] result = new Integer[src.length];
        int temp;
        int c = src.length;
        //倒序
        if(isAsc == false){
            for (int i = 1;i<c;i++) {
                for (int j = 0;j<i-1;j++) {
                    if(src[j]<src[j+1]){
                        temp = src[j+1];
                        src[j+1] = src[j];
                        src[j] = temp;
                    }
                }
            }
        }else{
        //正序
            for (int i = 1;i<c;i++) {
                for (int j = 0;j<i-1;j++) {
                    if(src[j]<src[j+1]){
                        temp = src[j+1];
                        src[j+1] = src[j];
                        src[j] = temp;
                        System.out.println(Arrays.toString(src));
                    }
                }
            }
        }

        return src;
    }
}
